package com.nulldev.util.graphics.renderIt.api.core;

import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.graphics.renderIt.api.renderItConstants;
import com.nulldev.util.graphics.renderIt.api.envcaps.renderItCanvasOperations;

public interface IRenderCanvas {
	default void unsupported() {
		throw new UnsupportedOperationException("Unsupported canvas operation!");
	}

	default <T> T ret_unsupported() {
		throw new UnsupportedOperationException("Unsupported canvas operation!");
	}

	default void unsupported(final renderItCanvasOperations op) {
		throw new UnsupportedOperationException("Missing canvas operation support! (" + op + ")");
	}

	default <T> T ret_unsupported(final renderItCanvasOperations op) {
		throw new UnsupportedOperationException("Missing canvas operation support! (" + op + ")");
	}

	public abstract renderItCanvasOperations[] supportedOperations();

	public default boolean supportsOperation(final renderItCanvasOperations operation) {
		return ArrayUtils.contains(supportedOperations(), operation);
	}

	/* RIT_canvas_title */

	public default String canvas_getTitle() {
		return this.ret_unsupported(renderItCanvasOperations.RIT_canvas_title);
	}

	public default void canvas_setTitle(final String title) {
		this.unsupported(renderItCanvasOperations.RIT_canvas_title);
	}

	/* RIT_canvas_bounds */

	public default int canvas_getWidth() {
		return renderItConstants.RIT_NOT_SUPPORTED;
	}

	public default int canvas_getHeight() {
		return renderItConstants.RIT_NOT_SUPPORTED;
	}

	public default void canvas_setWidth(final int width) {
		this.unsupported(renderItCanvasOperations.RIT_canvas_bounds);
	}

	public default void canvas_setHeight(final int height) {
		this.unsupported(renderItCanvasOperations.RIT_canvas_bounds);
	}

	/* RIT_canvas_position */

	public default int canvas_getPosX() {
		return renderItConstants.RIT_NOT_SUPPORTED;
	}

	public default int canvas_getPosY() {
		return renderItConstants.RIT_NOT_SUPPORTED;
	}

	public default void canvas_setPosX(final int x) {
		this.unsupported(renderItCanvasOperations.RIT_canvas_position);
	}

	public default void canvas_setPosY(final int y) {
		this.unsupported(renderItCanvasOperations.RIT_canvas_position);
	}

	/* RIT_canvas_visibility */

	public default boolean canvas_isVisible() {
		return true;
	}

	public default void canvas_setVisible(final boolean visible) {
		this.unsupported(renderItCanvasOperations.RIT_canvas_visibility);
	}

	/* RIT_output_awt_component */

	public default Object asAWTComponent() {
		return this.ret_unsupported(renderItCanvasOperations.RIT_output_awt_component);
	}

	/* RIT_output_swing_component */

	public default Object asSwingComponent() {
		return this.ret_unsupported(renderItCanvasOperations.RIT_output_awt_component);
	}

	/* RIT_canvas_callback */

	public void setRenderCallback(final IRenderCallback iRenderCallback);

	public default void start() {
	}

	/* RIT_canvas_fullscreen */

	public default boolean canvas_isFullscreen() {
		return false;
	}

	public default boolean canvas_makeFullscreen(final boolean state) {
		if (!state)
			return true;
		return false;
	}

	public default void canvas_setFullscreen(final boolean state) {
		this.unsupported(renderItCanvasOperations.RIT_canvas_fullscreen);
	}

	/* RIT_graphics_deferred */

	public default boolean graphics_isDeferred() {
		return false;
	}

	public default void graphics_setDeferred(final boolean state) {
		this.unsupported(renderItCanvasOperations.RIT_graphics_deferred);
	}

	public default void graphics_requestRepaint() {
	}
}
